package offer;

public class Offer33 {

        public boolean verifyPostorder(int[] postorder) {
            if(postorder.length==0) return true;
            return recur(postorder,0,postorder.length-1);
        }

        public boolean recur(int[] postorder,int i,int j){
            if(i>=j) return true;
            int p =i;
            while(postorder[p]< postorder[j]) p++;
            int m = p;
            while(postorder[p]>postorder[j]) p++;
            return p==j && (recur(postorder,i,m-1) && recur(postorder,m,j-1));
        }



    public static void main(String[] args) {

        Offer33 offer33 = new Offer33();
        int [] nums={1,3,2,6,5};
        System.out.println(offer33.verifyPostorder(nums));
    }



}
